package com.stage.calculator;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * Created by fadinglan on 2017/4/18.
 */
public class SysContextListenser implements ServletContextListener {

    private StageSleep task = null;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {

        ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
        ExecutorService executor = Executors.newCachedThreadPool();
        task = new StageSleep(servletContextEvent.getServletContext(), scheduler, executor);
        servletContextEvent.getServletContext().log("分期服务启动");
        task.taskBegin();
    }
    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        task.taskEnd();
        servletContextEvent.getServletContext().log("分期服务销毁");

    }
}
